package com.littlepay.kr4.paulin.dfeba77.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import com.littlepay.kr4.paulin.dfeba77.R;
import com.littlepay.kr4.paulin.dfeba77.application.MyApplication;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 77dfeba on 2017/5/2.
 * CostPanelUtil is to select the attribution of every cost
 * maybe can add user-define attribution
 */

public class CostPanelUtil {
    private Context context;
    private Activity activity;
    private GridView gridView;
    private List<Map<String, Object>> data_list;
    private SimpleAdapter sim_adapter;
    private Button timeButton;
    public CostPanelUtil(Activity activity, Context context){
        this.context = context;
        this.activity = activity;
    }
    private static final int[] icon = {
            R.drawable.btn_addspend_more,R.drawable.btn_addspend_eat,R.drawable.btn_addspend_taxi, R.drawable.btn_addspend_shop,R.drawable.btn_addspend_recreation,
            R.drawable.btn_addspend_live, R.drawable.btn_addspend_borrow, R.drawable.btn_addspend_beauty, R.drawable.btn_addspend_health, R.drawable.btn_addspend_pet,
    };
    public void creatPanel(){
        gridView = (GridView) activity.findViewById(R.id.cost_select);
        timeButton = (Button) activity.findViewById(R.id.date_select_btn);
        timeButton.setText("  今日 "+DateUtil.getTodayDate()+"  ");
        //新建List
        data_list = new ArrayList<>();
        //获取数据
        getData();
        //新建适配器
        String [] from ={"image"};
        int [] to = {R.id.grid_image};
        sim_adapter = new SimpleAdapter(context, data_list, R.layout.gridview_item, from, to);
        //配置适配器
        gridView.setAdapter(sim_adapter);
//        gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
//            @Override
//            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
//                Toast.makeText(MyApplication.getInstance().getContext(),"位置是"+i,Toast.LENGTH_SHORT).show();
//
//                return true;//事件不扩散
//            }
//        });
    }
    private List<Map<String, Object>> getData(){
        //cion和iconName的长度是相同的，这里任选其一都可以
        for (int anIcon : icon) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("image", anIcon);
            //map.put("text", iconName[i]);
            data_list.add(map);
        }
        return data_list;
    }
    public void showCostPanel(){
        creatPanel();
        if(gridView.getVisibility() == View.INVISIBLE || gridView.getVisibility() == View.GONE){
            gridView.setVisibility(View.VISIBLE);
        }
    }


}
